<?php
class SF_CategoryPage_Block_Such extends Mage_Catalog_Block_Product_Abstract
    //Mage_Core_Block_Template
{
    protected function _toHtml()
    {
        return parent::_toHtml();
    }

    public function codeId(){ //当前分类ID
        $codeId = $this->getRequest()->getParam("code");
        return $codeId;
    }

    public function bannerIds(){ //列表聚合页分类Banner ID
        $codeId = $this->codeId();
        $bannerIds  = $this->codes('bannerIds');
        $banner = array();
        $products = '';
        foreach ($bannerIds[$codeId] as $val) {
            $loadCategory   = Mage::getModel('catalog/category')->load($val);
            if(!$loadCategory) continue;
            $banner[$val]['url']  = $loadCategory->getUrl();
            $banner[$val]['name'] = $loadCategory->getName();
            $collection = $this->screenIds($val,'1');
            foreach ($collection as $_product){
                $bannerImg = (string)Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(190);
                $products .= '<div><a href="'.$loadCategory->getUrl().'"><img src="'.$bannerImg.'" alt=""></a><h3><a href="'.$banner[$val]['url'] .'">'.$banner[$val]['name'].'</a></h3></div>';
            }
            
        }
        
        return $products; /* return string */
    }

    public function screenIds($categoryId,$number){ //通过分类id筛选产品
        $page   = '1';
        $productIds = array();
        $loadCategory   = Mage::getModel('catalog/category')
            ->load($categoryId)
            ->getProductCollection()
            //->addAttributeToSelect('*')
            ->addAttributeToSelect('id')
            ->addAttributeToSelect('name')
            ->addUrlRewrite()
            ->addAttributeToSelect('short_description')
            ->addAttributeToSelect('thumbnail')
            ->addAttributeToSelect('pirce')
            ->addFinalPrice()
            ->addAttributeToFilter('status', 1)
            ->addAttributeToFilter('visibility', 4)
            ->addAttributeToFilter('approval', 2)
            ->setPageSize(intval($number))
            ->setCurPage(intval($page))
            ->setOrder('updated_at','desc')
            ->addAttributeToFilter('updated_at',
                array('gteq' => date('Y-m-d H:i:s',strtotime("-10 week")))
            );

        return $loadCategory;
    }

    public function categoryIds(){ //列表聚合页分类ID
        $codeId = $this->codeId();
        $categoryIds  = $this->codes('categoryIds');
        return $categoryIds[$codeId];
    }

    public function codeColor() { //列表聚合页分类颜色
        $codeId = $this->codeId();
        $codeColor = $this->codes('codeColor');
        return $codeColor[$codeId];
    }
    public function codeName(){ //列表聚合页分类Name
        $codeId = $this->codeId();
        $codeName = $this->codes('codeName');
        return $codeName[$codeId];
    }
    public function codes($codes){
        $codeIds = array(
            'codeName' => array(
                '1066' => array('Clothing & Accessories','Одежда и аксессуары'),
                '1067' =>array ('Shoes & Bags','Обувь и сумки'),
                '537'  =>array ('Phones & Accessories','Телефоны и аксессуары'),
                '586'  =>array ('Computers, Tablets & Office','Компьютеры и офисная техника'),
                '6'     =>array ('Consumer Electronics','Электроника'),
                '792'  =>array ('Sports & Outdoor living, Hobbies','Спорт, туризм, хобби'),
                '726'  =>array ('Health & Beauty','Красота и здоровье'),
                '1068' =>array ('Mother & Kid, Toy','Для мам и малышей'),
                '394'  =>array ('Home & Garden','Товары для дома и сада'),
                '484'  =>array ('Auto & Motor','Авто и Мототовары'),
            ),
            'codeColor'=> array(
                '1066' =>'#f72e36',
                '1067' =>'#f05b19',
                '537' =>'#1482c1',
                '586' =>'#274aa4',
                '6' =>'#2963b5',
                '792' =>'#f57a1a',
                '726' =>'#ca389d' ,
                '1068' =>'#f9b016' ,
                '394' =>'#3dba6c',
                '484' =>'#32485d',
            ),
            'categoryIds'  => array(
                '1066' => array('201','158','853','288','300','715','709','700','693','1009'),
                '1067' => array('313','329','341','1044','353','364','817'),
                '537'  => array('538','556','553','555','558','561','1010','562','557','559','1058'),
                '586'  => array('587','593','609','769','613','616','626','631','645'),
                '6'    => array('786','7','37','56','70'),
                '792'  => array('843','944','919','855,','816','555','57','11','976'),
                '726'  => array('727','732','1012','741','747','751','758','760','1062'),
                '1068' => array('288','300','341','785'),
                '394'  => array('395','438','477','425','461','456','1060','116',),
                '484'  => array('485','495','508','519','524','1010'),
            ),
            'bannerIds'  => array(
                '1066' => array('201','158','853','693','700','715',),
                '1067' => array('353','364','817','313','329','1044',),
                '537'  => array('539','561','555','553','558','1010',),
                '586'  => array('587','619','630','598','631','645',),
                '6'    => array('786','7','41','42','56','70',),
                '792'  => array('843','944','855','11','555','976',),
                '726'  => array('727','732','751','747','760','741',),
                '1068' => array('288','300','341','785','790','998',),
                '394'  => array('395','461','477','438','425','116',),
                '484'  => array('486','487','495','525','1010','536',),
            ),
        );
        return $codeIds[$codes];
    }
}

